var gulp = require('gulp'),
    uglify = require('gulp-uglify'),
    imagemin = require('gulp-imagemin'),
    minifycss = require('gulp-minify-css'),
    cleancss = require('gulp-clean-css'),
    less = require('gulp-less'),
    template = require('gulp-template'),
    del = require('del'),
    gulpsync = require('gulp-sync'),
    path = require('path')

gulp.task('minify-js', () => {
    gulp.src(['js/**/*.js', 'js/*.js'])
        .pipe(uglify())
        .pipe(gulp.dest('dist/js'))
})

gulp.task('minify-img', () => {
    gulp.src('./img/*')
        .pipe(imagemin())
        .pipe(gulp.dest('dist/img'))
})

gulp.task('minify-css', () => {
    gulp.src(['./css/*.css', './css/**/*.css'])
        .pipe(cleancss({ compatibility: 'ie8' }))
        .pipe(gulp.dest('dist/css'))
})

gulp.task('minify-tpl', () => {
    gulp.src('./tpl/*.html')
        .pipe(template({ name: 'Sindre' }))
        .pipe(gulp.dest('dist/tpl'))
})

gulp.task('minify-html', () => {
    gulp.src(['share.html'])
        .pipe(template({ name: 'Sindre' }))
        .pipe(gulp.dest('dist'))
})

gulp.task('less', function () {
    gulp.src('./less/**/*.less')
        .pipe(less({
            paths: [path.join(__dirname, 'less', 'includes')]
        }))
        .pipe(gulp.dest('./css/style'))
})

gulp.task('clean', () => {
    del(['./dist'])
})

gulp.task('watch', () => {
    gulp.watch('./less/**/*.less', ['less'])
})

gulp.task('minify', ['minify-js', 'minify-img', 'minify-css', 'minify-html'])